package cn.com.blueInfo.bpm.system.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.system.request.ResourceDTO;
import cn.com.blueInfo.bpm.system.response.ResourceVO;
import cn.com.blueInfo.bpm.system.service.ResourceService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 资源表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:37:55
 */
@Tag(name = "资源 接口")
@RestController
@RequestMapping("/system/resource")
public class ResourceController extends BaseController {

    @Autowired
    private ResourceService resourceService;

    /**
     * 新建资源
     * @param resourceDTO 资源参数
     * @return ResultInfo
     */
    @Operation(summary = "新增资源")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createResource(
            @Validated({Create.class, Default.class}) @RequestBody ResourceDTO resourceDTO) {
        return resourceService.addResource(resourceDTO);
    }

    /**
     * 批量新建资源
     * @param resourceDTOList 资源参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建资源")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateResource(
            @Validated({Create.class, Default.class}) @RequestBody List<ResourceDTO> resourceDTOList) {
        return resourceService.batchAddResource(resourceDTOList);
    }

    /**
     * 根据ID删除资源
     * @param resourceId 资源ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除资源")
    @DeleteMapping("/removeInfo/{resourceId}")
    public ResultInfo<Integer> deleteResourceById(
            @Parameter(name = "ID") @PathVariable Long resourceId) {
        return resourceService.removeResource(resourceId);
    }

    /**
     * 批量根据ID删除资源
     * @param resourceIdList 资源ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除资源")
    @DeleteMapping("/removeInfoList/{resourceIdList}")
    public ResultInfo<Integer> deleteResourceById(
            @Parameter(name = "ID") @PathVariable List<Long> resourceIdList) {
        return resourceService.batchRemoveResource(resourceIdList);
    }

    /**
     * 根据ID全量更新资源
     * @param resourceId 资源ID
     * @param resourceDTO 资源参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新资源")
    @PutMapping("/modifyInfo/{resourceId}")
    public ResultInfo<Integer> updateResourceFull(
            @Parameter(name = "ID") @PathVariable Long resourceId,
            @Validated({Update.class, Default.class}) @RequestBody ResourceDTO resourceDTO) {
        validateUpdateId(resourceId, resourceDTO.getId());
        return resourceService.modifyResource(resourceDTO);
    }

    /**
     * 根据ID部分更新资源
     * @param resourceId 资源ID
     * @param resourceUpdatePartialDTO 资源参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新资源")
    @PatchMapping("/modifyPartialInfo/{resourceId}")
    public ResultInfo<Integer> updateResourcePartial(
            @Parameter(name = "ID") @PathVariable Long resourceId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            ResourceDTO.UpdatePartialDTO resourceUpdatePartialDTO) {
        validateUpdateId(resourceId, resourceUpdatePartialDTO.getId());
        return resourceService.modifyResourcePartial(resourceUpdatePartialDTO);
    }

    /**
     * 根据ID查询资源
     * @param resourceId 资源ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询资源")
    @GetMapping("/getInfo/{resourceId}")
    public ResultInfo<ResourceVO> getResourceById(
            @Parameter(name = "ID") @PathVariable Long resourceId) {
        return resourceService.queryResourceById(resourceId);
    }

    /**
     * 分页查询资源
     * @param resourceQueryDTO 资源参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询资源")
    @GetMapping("/getInfos")
    public ResultInfo<Page<ResourceVO>> getResourcePage(
            @Validated ResourceDTO.QueryDTO resourceQueryDTO) {
        return resourceService.queryResourcePage(resourceQueryDTO);
    }

    /**
     * 根据条件查询资源
     * @param resourceQueryDTO 资源参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询资源")
    @GetMapping("/getInfoList")
    public ResultInfo<List<ResourceVO>> getResourceList(
            @Validated ResourceDTO.QueryDTO resourceQueryDTO) {
        return resourceService.queryResourceList(resourceQueryDTO);
    }

}
